#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;

struct Student{
    int id;
    double grade[4];//A C M E
    // 4ci cunxialai
}stu[2001];
double eps = 1e-9;
bool cmp(Student a,Student b){
    if(abs(a.grade[0]-b.grade[0])>eps)
        return a.grade[0]>b.grade[0];
    if(abs(a.grade[1]-b.grade[1])>eps)
        return a.grade[1]>b.grade[1];
    if(abs(a.grade[2]-b.grade[2])>eps)
        return a.grade[2]>b.grade[2];
    if(abs(a.grade[3]-b.grade[3])>eps)
        return a.grade[3]>b.grade[3];
    return a.id<b.id;        
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for (int i=0;i<n;i++){
        scanf("%lf%lf%lf%lf",&stu[i].id,&stu[i].grade[1],&stu[i].grade[2],&stu[i].grade[3]);
        stu[i].grade[0] = (stu[i].grade[1]+stu[i].grade[2]+stu[i].grade[3])/3;
    }
    sort(stu,stu+n,cmp);
    





    return 0;
}